package com.medical.manage.controller;


import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.medical.common.core.domain.Result;
import com.medical.common.core.utils.StringUtils;
import com.medical.manage.constant.Constant;
import com.medical.manage.domain.Video;
import com.medical.manage.service.VideoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author：waikaipeng
 * @Package：com.medical.video.controller
 * @Project：medical
 * @name：VideoController
 * @Date：2025年3月1日 01:14
 */
@RestController
@RequestMapping("/video")
public class VideoController {
     @Autowired
    private VideoService videoService;

     @Autowired
    private StringRedisTemplate redisTemplate;

     //视频列表
     @GetMapping("/list")
    public Result<Page<Video>> list(){
         Video video = new Video();
         Page<Video> pageList = new Page<>(video.getPageNum(), video.getPageSize());
         String s = (String) redisTemplate.opsForValue().get(Constant.SYNC_VIDEO_LIST);
         if (StringUtils.isNotBlank(s)){
             List<Video> videos = JSONObject.parseArray(s, Video.class);
         }
         return Result.success(videoService.page(pageList));
     }


     //视频数据添加

/**
 * 使用内置方法save(插入)
 *
 * @return
*/
 @PostMapping("/save")
   public Result save(@RequestBody Video video){
       return Result.success(videoService.save(video));
   }

    //批量插入数据。
    /**
     * 使批量插入数据。(插入)
     *
     * @return
     */
    @PostMapping("/saveBatch")
    public Result saveBatch(@RequestBody List<Video> videoList){
        return Result.success(videoService.saveBatch(videoList));
    }


    /**
     * 使用内置方法updateById(更新)
     *
     * @return
     */
    @PutMapping("/updateById")
    public Result updateById(@RequestBody Video video){
        return Result.success(videoService.updateById(video));
    }


    /**
     * 使用内置方法removeById(删除)
     *
     * @return
     */
    @DeleteMapping("/removeById")
    public Result removeById(@RequestParam("id") Integer id){
        return Result.success(videoService.removeById(id));
    }




}
